package com.example.listener;

import com.example.common.result.Result;
import com.example.common.util.SpringContextUtil;
import com.example.controller.FlowController;
import com.example.exception.BaseException;
import com.example.service.IActFlowCustomService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ApplicantTaskListener implements TaskListener {
    @Autowired
    private FlowController flowController;

    @Override
    public void notify(DelegateTask delegateTask) {
        Boolean taskResult = delegateTask.getVariableLocal("taskResult", Boolean.class);
        if (!taskResult) {
            Result result = flowController.shutDownReport(delegateTask.getProcessInstanceId(), "制单人自审撤销");
            if (!result.getCode().equals("200")) {
                throw new BaseException("取消上报失败！");
            }
        }
    }
}
